package com.neusoft.elmboot.util.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultBody {

    /**
     * 响应码
     */
    private String code;

    /**
     * 响应消息
     */
    private String message;

    /**
     * 响应结果
     */
    private Object result;

    public ResultBody(BaseResponseInfo baseResponseInfo){
        this.code = baseResponseInfo.getResultCode();
        this.message = baseResponseInfo.getResultMsg();
    }

    public static ResultBody success() {
        return success(null);
    }

    public static ResultBody success(Object data) {
        ResultBody rb = new ResultBody(CodeEnum.SUCCESS);
        rb.setResult(data);
        return rb;
    }

    public static ResultBody success(String message, Object data) {
        ResultBody rb = new ResultBody();
        rb.setCode(CodeEnum.SUCCESS.getResultCode());
        rb.setMessage(message);
        rb.setResult(data);
        return rb;
    }

    public static ResultBody error() {
        return error(null);
    }

    public static ResultBody error(Object data) {
        ResultBody rb = new ResultBody(CodeEnum.FAILED);
        rb.setResult(data);
        return rb;
    }

    public static ResultBody error(String message, Object data) {
        ResultBody rb = new ResultBody();
        rb.setCode(CodeEnum.FAILED.getResultCode());
        rb.setMessage(message);
        rb.setResult(data);
        return rb;
    }

}
